package ${package.Controller};

import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.enums.RetStatusNum;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.Valid;
import java.util.List;
import com.ml.mall.annotations.OperLog;
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};

</#if>

/**
* <p>
* ${table.comment!} controller
* </p>
*
* @author DaiZH
* Created ${date}
*/

@Api(tags = "")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} extends BaseController{
    </#if>

     @Autowired
     private ${table.serviceName} ${table.serviceName};


    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("")
    public ApiRestResult ${table.entityPath}Query(@RequestBody Object object) {
        return ApiRestResult.ok(service.${table.entityPath}ByPage(object));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "", operModul = "", operType = "new")
    @ApiOperation("")
    public ApiRestResult ${table.entityPath}New(@Valid @RequestBody Object object ) {

        return ApiRestResult.ok(service.${table.entityPath}New(object));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @OperLog(operDesc = "", operModul = "", operType = "edit")
    @ApiOperation("")
    public ApiRestResult ${table.entityPath}Edit(@Valid @RequestBody Object object ) {

        return ApiRestResult.ok(service.${table.entityPath}Edit(object));
    }


    @RequestMapping(method = RequestMethod.DELETE, path = "/del")
    @OperLog(operDesc = "", operModul = "", operType = "del")
    @ApiOperation("")
    public ApiRestResult ${table.entityPath}Del(@RequestParam("ids") List<Long> ids) {
        if(ids==null||ids.size()<1){
            return ApiRestResult.err(RetStatusNum.PARAMS_ERROR.getMessage(), RetStatusNum.PARAMS_ERROR.getCode());
        }
        return ApiRestResult.ok(service.${table.entityPath}Del(ids));
    }
}
</#if>
